﻿using CardPlay.Model.CardModel;
using CardPlay.Model.GameModel;
using CardPlay.Model.GameModel.Actions;
using CardPlay.Model.GameModel.Presentation;
using CardPlay.Model.Layout;

namespace CardPlay.DemoPack.Games.KlondikeVariants
{
    [Game("35AD755D-EEE8-4B1F-8B5A-ED645E54A542", LevelOfDifficulty.Medium, LevelOfSkill.ModerateSkill, DurationOfPlay.Within5To10Minutes, 
        NumberOfDecks = 2, Family = FamilyName)]
    public class Batsford : Klondike
    {
        public Batsford()
        {
            NamesOfAdditionalPiles.Add(Reserve);

            MaximumDeals = 1;
            TotalDecks = 2;
            TotalFoundations = 8;
            TotalTableaus = 10;
        }

        protected override ILayoutSite CreateTableauPresentation(IPresentationContext presentation)
        {
            var finalRow = presentation.CreateRowLayout(); // CreateSideBySideLayout(presentation.Metrics);

            var reserveStyle = new VisualTraits
                               {
                                   EmptyCue = () => EmptyPileCue.CardSite,
                                   Arrangement = CardArrangement.StackSquare,
                                   ContentFit = ContentFit.FitBounds
                               };

            finalRow.Add(presentation.CreatePileVisual(Reserve, reserveStyle));
            finalRow.Add(base.CreateTableauPresentation(presentation));

            return finalRow;
        }

        protected override void OverridePlayingRules(PlayingRules playingRules)
        {
            playingRules.At(Reserve).Permit<MovePileAction>().When(action => 
                action.TargetPile.Count < 3 &&
                action.IsMovingSingleCard() && 
                action.PileBeingMoved.BottomCard.Rank == Rank.King && ! action.CardGame.AnyEmptyPilesNamed(AnyTableau));
        }
    }
}